﻿using System.Collections.Generic;
using System.Text;
using Core.Domain;

namespace Core.SyntaxAnalysis.Classes
{
    public class Stmts
    {
        private readonly Stmt m_current;
        private List<Stmt> m_next;

        public Stmts(Stmt current)
        {
            m_current = current;
        }

        public void Append(Stmt next)
        {
            if (m_next == null)
            {
                m_next = new List<Stmt>();
            }
            m_next.Add(next);
        }

        public bool SemanticCheck(ref List<CompilerError> errors)
        {
            if (!m_current.SemanticCheck(ref errors))
            {
                return false;
            }
            if (m_next != null)
            {
                foreach (Stmt current in m_next)
                {
                    if (current != null)
                    {
                        if (!current.SemanticCheck(ref errors))
                        {
                            return false;
                        }
                    }
                }
            }
            return true;
        }

        public void Generate(StringBuilder s)
        {
            m_current.Generate(s);
            if (m_next != null)
            {
                foreach (Stmt stmt in m_next)
                {
                    stmt.Generate(s);
                }
            }
        }
    }
}